package com.parkingspace.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.parkingspace.dao.ParkingInformationMapper;
import com.parkingspace.entity.Order;
import com.parkingspace.entity.OrderQuery;
import com.parkingspace.entity.ParkingInformation;
import com.parkingspace.service.IOrderService;
import com.parkingspace.util.Constants;
import com.parkingspace.util.ResultVO;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author Gapper
 * @since 2021-05-24
 */
@RestController
@RequestMapping("/order")
public class OrderController {

	@Resource
	private IOrderService iOrderService;

	/**
	 * 存入车位出租分钟,放入消息队列中
	 * @param parkingId 车位ID
	 * @param carUid 租客uid
	 * @param time 出租分钟
	 */
	@PutMapping("/sendDlx/{parkingId}/{carUid}/{time}")
	public void sendDlx (@PathVariable(value = "parkingId") Long parkingId, @PathVariable("carUid") Long carUid,@PathVariable("time") String time) {
		iOrderService.sendDlx(parkingId,carUid,time);
	}

	/**
	 * 查询订单表的信息
	 * @param parkingId 传入车位ID
	 * @param token 传入令牌
	 * @param current 当前第几页
	 * @param size 每页显示条数
	 * @param order 订单条件
	 * @param start 起始时间
	 * @param end 结束时间
	 * @return 分页后的订单信息
	 */
	@GetMapping("/findAllOrder")
	public ResultVO findAllOrder (String token,
	                              Long parkingId,
	                             @RequestParam(defaultValue = "1") long current,
	                              @RequestParam(defaultValue = "3") long size,
	                              Order order,
	                              String start,
	                              String end) {
		try {
			Page<Order> allOrder = iOrderService.findAllOrder(parkingId, token, current, size, order, start, end);
			return new ResultVO(Constants.OPER_SUCCESS,"请求成功!",allOrder);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultVO(Constants.OPER_FAILURE,e.getMessage(),"请求失败!");
		}
	}

	@RequestMapping("/list")
	public ResultVO list(){
		List<OrderQuery> orderQueryList = iOrderService.findAll();
		return new ResultVO(Constants.OPER_SUCCESS,"查询成功",orderQueryList);
	}

}

